<?php if (!defined('THINK_PATH')) exit();?><style type="text/css">
    .add_table {
        width: 100%;
    }

    .add_table th {
        width: 140px;
        background-color: #E0ECFF;
        padding: 8px 0 8px 0;
        border-right: solid 1px #95B8E7;
        border-bottom: solid 1px #95B8E7;
    }

    .add_table td {
        border-bottom: solid 1px #95B8E7;
    }

    .add_table tr {
        border: solid 1px #95B8E7;
    }

    .inline {
        display: inline
    }

    .row_container {
        padding: 8px 5px 5px 5px;
    }
</style>
<!-- 工具栏 -->
<div style="background-color: #E0ECFF;">
    <table>

        <tr>
            <td>
                <a href="#" class="easyui-linkbutton" onclick='submit_edit_zds("save")'
                   data-options="iconCls:'icon-ok',plain:true">保存</a>
                <a href="#" class="easyui-linkbutton" onclick='submit_edit_zds("will_check")'
                   data-options="iconCls:'icon-ok',plain:true">发布</a>
                <a href="#" class="easyui-linkbutton" onclick="FullScrean()"
                   data-options="iconCls:'icon-standard-monitor',plain:true">全屏</a>

                <a href="#" class="easyui-linkbutton" onclick='go_back_zds("<?php echo ($data[id]); ?>")'
                   data-options="iconCls:'icon-back',plain:true">返回</a>

                <!--<a href="#" class="easyui-linkbutton"-->
                   <!--onclick='vbaa(1,"http://192.168.8.200/solve/Public/images/fjp203.png",5)'-->
                   <!--data-options="iconCls:'icon-back',plain:true">测试vba功能</a>-->
                <!--<a href="#" class="easyui-linkbutton" onclick='testt()' data-options="iconCls:'icon-back',plain:true">测试vba功能2</a>-->
                <!--<input type="text" id="textval">-->
                <!--<a href="#" class="easyui-linkbutton" onclick='shuiyin()' data-options="iconCls:'icon-back',plain:true">水印</a>-->
                <!--<a href="#" class="easyui-linkbutton" onclick='vbadocument()'-->
                   <!--data-options="iconCls:'icon-back',plain:true">vba功能测试</a>-->

                <!--<a href="#" class="easyui-linkbutton" onclick='DownLoadReportIMG("http://192.168.8.200/solve/public/upload/sign/2018-03-09/5aa24b1dada25.png")'-->
                   <!--data-options="iconCls:'icon-back',plain:true">dddd</a>-->


                <!--<a href="#" class="easyui-linkbutton" onclick='about()' data-options="iconCls:'icon-back',plain:true">关于1</a>-->
            </td>

        </tr>

    </table>
</div>


<div id="ccdoc" class="easyui-layout" data-options="fit:true">

    <div data-options="region:'west',title:'West',title:'表头信息',split:true,hideCollapsedContent:false"
         style="width:550px;">
        <form id="edit_zds_form" enctype="multipart/form-data" method="post">

            <table class="add_table">
                <tr>

                    <td>
                        <div class="row_container">

                            <div class="inline">
                                <span class="add_label">标题：</span>
                                <input id="edit_title" name="title" class="easyui-textbox"
                                       data-options="iconCls:'',multiline:true,editable:true,required:true"
                                       style="width:360px;height:80px;" value='<?php echo ($data["title"]); ?>'/>
                            </div>

                        </div>
                    </td>
                </tr>
                <tr>

                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">车间：</span>
                                <input id="cj_edit" name="cj" class="easyui-textbox"
                                       data-options="iconCls:'',editable:true,required:true,panelHeight:'auto'"
                                       style="width:100px" value='<?php echo ($data["cj"]); ?>'/>
                            </div>
                            <div class="inline">
                                <span class="add_label">工位：</span>
                                <input id="gw_edit" class="easyui-combogrid" data-options="editable:false,required:true"
                                       name="gw[]" style="width:200px;" value='<?php echo ($data["gw"]); ?>'/>


                            </div>


                        </div>
                    </td>
                </tr>
                <tr>

                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">适用车型:</span>
                                <input id="cx_edit" name="cx" class="easyui-textbox"
                                       data-options="iconCls:'',editable:true,required:true" style="width:300px"
                                       value='<?php echo ($data["cx"]); ?>'/>
                            </div>


                        </div>
                    </td>
                </tr>
                <tr>

                    <td>
                        <div class="row_container">

                            <div class="inline">
                                <span class="add_label">配置:</span>
                                <input id="pz_edit" name="pz" class="easyui-textbox"
                                       data-options="iconCls:'',editable:true,required:true" style="width:360px"
                                       value='<?php echo ($data["pz"]); ?>'/>
                            </div>


                        </div>
                    </td>
                </tr>
                <tr>

                    <td>


                        <div class="inline">
                            <span class="add_label">分组：</span>
                            <input id="fz_edit" class="easyui-combogrid" data-options="editable:true,required:false"
                                   name="fz[]" style="width:450px;" value='<?php echo ($data["fz"]); ?>'/>

                        </div>


                    </td>
                </tr>
                <tr>

                    <td>
                        <div class="row_container">

                            <div class="inline">
                                <span class="add_label">适用字组：</span>
                                <input  name="syfz" class="easyui-textbox"
                                        data-options="iconCls:'',multiline:true,editable:true,required:true,validType:'syfz',prompt:'只能输入英文大写字母、数字，并以英文“,”隔开！'"
                                        style="width:360px;height:80px;" value='<?php echo ($data["syfz"]); ?>'/>

                            </div>
                        </div>
                    </td>
                <tr>
                <tr>
                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">校对</span>
                                <input id="edit_s1" class="easyui-combobox" name="s1id"
                                       data-options="valueField:'value',textField:'text',url:'/solve/index.php/Admin/Public/user1',panelHeight:'auto'"
                                       style="width:100px;" value='<?php echo ($data["s1id"]); ?>'/>
                            </div>

                            <div class="inline">
                                <span class="add_label">审核：</span>
                                <input id="edit_s2" class="easyui-combobox" name="s2id"
                                       data-options="valueField:'value',textField:'text',url:'/solve/index.php/Admin/Public/zhuguan',panelHeight:'auto'"
                                       style="width:100px;" value='<?php echo ($data["s2id"]); ?>'/>

                            </div>
                            <div class="inline">
                                <span class="add_label">批准：</span>
                                <input id="edit_s3" class="easyui-combobox" name="s3id"
                                       data-options="valueField:'value',textField:'text',url:'/solve/index.php/Admin/Public/buzhang',panelHeight:'auto'"
                                       style="width:100px;" value='<?php echo ($data["s3id"]); ?>'/>
                            </div>


                        </div>

                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="row_container">

                            <div class="inline">
                                <span class="add_label">发放单位</span>
                                <input id="edit_ffdw" class="easyui-combogrid"
                                       data-options="editable:true,required:false" name="ffdw[]" style="width:450px;"
                                       value='<?php echo ($data["ffdw"]); ?>'/>
                            </div>

                        </div>

                    </td>
                </tr>
            </table>


            <input type="hidden" name="uid" id="userid" value=<?php echo ($_SESSION['uid']); ?>>


            <!--     <input type="hidden" name="author" id="author" value= <?php echo ($_SESSION['uname']); ?>> -->
            <input type="hidden" name="nickname" id="nickname" value=<?php echo ($_SESSION['unickname']); ?>>

            <input type="hidden" id="edit_zds_id" name="id" value="<?php echo ($data['id']); ?>">
            <input type="hidden" id="docname" name="docname" value="<?php echo ($data['urls']); ?>">

        </form>


    </div>
    <div data-options="region:'center',title:''" style="padding:0px;background:#eee;">

        <?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome')): ?><object id='WebOffice1' type='application/x-itst-activex' align='baseline' border='0'
                    style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%'
                    clsid='{E77E049B-23FC-4DB8-B756-60529A35FAD5}'
                    event_NotifyCtrlReady='WebOffice1_NotifyCtrlReady'>
            </object><?php endif; ?>
        <?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')): ?><OBJECT id='WebOffice1' align='middle' style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%'
                    classid='clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5'
                    event_NotifyCtrlReady='WebOffice1_NotifyCtrlReady'>
            </OBJECT><?php endif; ?>
        <?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')): ?><object id='WebOffice1' type='application/x-itst-activex' align='baseline' border='0'
                    style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%'
                    clsid='{E77E049B-23FC-4DB8-B756-60529A35FAD5}'
                    event_NotifyCtrlReady='WebOffice1_NotifyCtrlReady'>
            </object><?php endif; ?>

    </div>
</div> 



<script src="/solve/Public/App/zds/word.js"></script>
<script type="text/javascript">
    function windowMask() {
        $(".window-mask").append("<iframe style=\"position: absolute; z-index: -1; width: 100%; height: 100%; top: 0;left:0;scrolling:no;\" frameborder=\"0\"></iframe>");
    }




   $(function(){
 // 当关闭tab时，销毁weboffice
// $('#tab').tabs({
//   onBeforeClose: function(title,index){
//     if($('#WebOffice1')){
//          $('#WebOffice1').remove();
//     }
//   }
// });
  })
   // 初始化
    function WebOffice1_NotifyCtrlReady(){
         webObj.ShowToolBar=false;
    
        // 隐藏工具栏
        // webObj.ShowToolBar=false;
        // vNew  = 0x01,             //新建
//         vOpen = 0x02,            //打开
//         vSaveAs = 0x04,          //保存
//         vPrint = 0x10,          //打印
//         vPrintView = 0x20,      //打印预览
//         vReturn = 0x1000,       //全屏
// vShowHideMenu = 0x4000, //显示/隐藏菜单
//         vFullScrean = 0x2000    //返回
    var id=$("#id").val();
    var docname=$("#docname").val();
webObj.LoadOriginalFile('http://192.168.8.200/wordupload/'+docname, "doc");  
// ProtectFull();//文档保护
UnProtect();//解除文档保护




    }

function about(){
    webObj.AboutBox();
   
}
function vbaa(strMarkName,strBmpPath,vType){
///////////////////////////////////////////
   webObj.SetFieldValue("cx","11", ""); //
// webObj.SetFieldValue("zp","", "");


    webObj.SetFieldValue("zp","http://192.168.8.200/solve/Public/images/fjp203.bmp", "::JPG::");
}
function vbaa1(strMarkName,strBmpPath,vType){
    strBmpPath="D:\\ddd.jpg";
    var obj;
         obj = new Object(webObj.GetDocumentObject());
         // obj = webObj.ActiveDocument;


         if(obj !=null){
               var pBookMarks;
// VAB接口获取书签集合
                   pBookMarks = obj.Bookmarks;
                   var pBookM;

            // console.log(JSON.stringify(pBookMarks));

//  var bks=obj.Application.ActiveDocument.Bookmarks(2).Name;


//       console.log(bks);
// // VAB接口获取书签strMarkName
// if(pBookMarks.Exists('zp')==true){
//     console.log('true')
// }else{
//     // console.log(pBookMarks.html())

  
// }
                   pBookM = pBookMarks.Item(strMarkName);
// console.log('pBookM');
//              console.log(pBookM);

                   var pRange;
// VAB接口获取书签strMarkName的Range对象
                   pRange = pBookM.Range;
                   var pRangeInlines; 
// VAB接口获取书签strMarkName的Range对象的InlineShapes对象
                   pRangeInlines = pRange.InlineShapes;
                   var pRangeInline; 
// VAB接口通过InlineShapes对象向文档中插入图片
                   pRangeInline = pRangeInlines.AddPicture(strBmpPath); 
 pRangeInline.Width =80;
                        pRangeInline.Height = 14;

//设置图片的样式，5为浮动在文字上面
                   pRangeInline.ConvertToShape().WrapFormat.TYPE = vType;
                   delete obj; 
   }

// console.log(obj);
}


function submit_edit_zds(para) {
var isValid = $('#add_zds_form').form('validate');
    if (!isValid) {
        $.messager.alert('警告','请输入文档必要信息');
        windowMask();
    } else {
        // 文档是否打开（是否有内容）
        var isOpen = webObj.IsOpened();
        var obj;
        obj = new Object(webObj.GetDocumentObject());
        if (isOpen > 0) {
            var id = $('#edit_zds_id').val();
            $('#edit_zds_form').form('submit', {
                url: APP+'/Home/Zds/edit',
                onSubmit: function (param) {
                    param.status = para;
                    param.content = obj.Content.Text; //文档内容
                },
                success: function (data) {
                    data = $.parseJSON(data);
                    if (data.status == 1) {
                        try {
                            var returnValue;
                            webObj.HttpInit();
                            // 添加相应的Post元素
                            // if (para == 'will_check') {
                            //     webObj.HttpAddPostString("ids", data.ids);
                            //     UnProtect();
                            //     webObj.SetFieldValue('ids', data.ids, "");//编制
                            //     ProtectFull();
                            //
                            //     // console.log(data)
                            // } else {
                            //     webObj.HttpAddPostString("ids", '');
                            //     UnProtect();
                            //     webObj.SetFieldValue('ids', '', "");//编制
                            //     ProtectFull();
                            // }
// 更新word中的标签
                            webObj.HttpAddPostString("ids", '');
                            var cx = $('#cx_edit').textbox('getText');
                            var pz = $('#pz_edit').textbox('getText');
                            var gw = $('#gw_edit').combogrid('getText');
                            var gxname = $('#edit_title').textbox('getText');

                            var s1 = $('#nickname').val();//编制
                            var s1time = new Date().Format("yyyy-MM-dd");//编制日期
                            // webObj.SetFieldValue("s1", s1, "");//编制
                            // webObj.SetFieldValue("s1time", s1time, "");//编制日期
                            webObj.SetFieldValue("cx", cx, "");//车型
                            webObj.SetFieldValue("pz", pz, "");//配置
                            webObj.SetFieldValue("gw", gw, "");//工位
                            webObj.SetFieldValue("gxname", gxname, "");//工序名称

                            newSave();//保存
                            webObj.HttpAddPostString("ida", data.id);
                            webObj.HttpAddPostString("title", $('#edit_title').textbox('getText'));
                            webObj.HttpAddPostString("DocType", "doc");
                            webObj.HttpAddPostCurrFile("DocContent", "");


                            returnValue = webObj.HttpPost('http://192.168.8.200/wordupload/savedoc.php?id=' + id + '&number=Math.random()');  // 判断上传是否成功
                            // console.log(returnValue);


                            if (returnValue == "succeed") {
                                $.messager.confirm('确认', data.msg + '您想要返回列表页面吗？', function (r) {
                                    if (r) {
                                        var tab = $('#tab').tabs('getSelected');
                                        if ($('#WebOffice1')) {
                                            $('#WebOffice1').remove();
                                        }
                                        //encodeURI() 函数可把字符串作为 URI 进行编码
                                        tab.panel('refresh', APP + '/Home/Zds/showEditor');
                                    }
                                });
                                windowMask();

                            } else if (returnValue == "failed")
                                $.messager.alert('失败', data.msg);
                            windowMask();

                        } catch (e) {
                            $.messager.alert('异常', "异常\r\nError:" + e + "\r\nError Code:" + e.number + "\r\nError Des:" + e.description);
                            windowMask();
                        }

                    } else {
                        $.messager.alert('失败', data.msg);
                        windowMask();

                    }

                }
            });
        } else {
            $.messager.alert('失败', 'word没有写入内容！');
            windowMask();
        }
    }
}





var cj = $('#cj_edit').combobox({ 
    valueField:'id', 
    url: APP+'/Admin/Trem/cjList',
    textField:'title', 
    editable:false,
    onSelect: function(rec){  
    
        $('#gw_edit').combogrid({    
        panelWidth:350,    
        idField:'title',    
        textField:'title',
        multiple:true,
        striped: true,    
        url:'/solve/index.php/Admin/Trem/cjList?pid='+rec.id,    
        columns:[[    
            {field:'title',title:'名称',width:120}  
        ]]    
        }); 
        $('#gw_edit').combogrid('setValue','');  
        }

     }); 





  $('#fz_edit').combogrid({
   
        panelWidth:640,    
        idField:'dc',    
        textField:'dc',
        multiple:true,
        delay: 500,
    mode: 'remote',
        striped: true,    
        url:APP+'/Admin/Trem/fzhList',
        columns:[[    
            {field:'zc',title:'总成',width:120},
            {field:'dc',title:'dc',width:60},
            {field:'fzname',title:'分组名称',width:180},
            {field:'sm',title:'分组主要零部件',width:200},
            {field:'fzr',title:'负责人',width:80}  
        ]],
        fitColumns: true  
        });

        function go_back_zds(id) {
            $.messager.confirm('确认','返回前需要保存吗？',function(r){
                if (r){
                    var s = savezds(id);
                }
            });

            windowMask();

            setTimeout(function () {
                var tab = $('#tab').tabs('getSelected');
                if ($('#WebOffice1')) {
                    $('#WebOffice1').remove();
                }
//encodeURI() 函数可把字符串作为 URI 进行编码
                tab.panel('refresh', APP+'/Home/Zds/showEditor');
            }, 2000);

        }

    $('#edit_ffdw').combogrid({

        panelWidth:450,
        idField:'dwname',
        textField:'dwname',
        multiple:true,
        delay: 500,
        mode: 'remote',
        striped: true,
        url:APP+'/Home/Word/ffdwList',
        columns:[[
            {field:'dwname',title:'单位',width:120},
            {field:'fzr',title:'负责人',width:300,
                formatter: function(value,row,index){
                    // console.log(value);
                    var str="";
                    if(value.length!=0){
                        var data=$.parseJSON(value);

                        for(var i=0;i<data.length;i++){
                            str=str+data[i].name+'('+data[i].email+')';
                            if(i!=data.length-1){
                                str=str+',';
                            }
                        }


                    }else{
                        str="";
                    }
                    return str;

                }
            }
        ]] ,
        fitColumns: false
    });

</script>